package com.hitqz.robot.biz.flow.component.agv;

import cn.hutool.json.JSONObject;
import com.hitqz.robot.api.common.entity.Robot;
import com.hitqz.robot.biz.flow.domain.constant.FlowConstant;
import com.hitqz.robot.biz.flow.util.LiteFlowUtil;
import com.hitqz.robot.biz.service.RobotService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;

/**
 * @author xupkun
 * @date 2025/2/21
 */
@Slf4j
@LiteflowComponent(value = "FetchAgvLeave", name = "[轮对/轮轴]AGV取轮起开后确认")
@RequiredArgsConstructor
public class FetchAgvLeave extends NodeComponent {

    private final RestTemplate restTemplate;

    private final RobotService robotService;

    @Override
    public void process() throws Exception {
        try {
            LiteFlowUtil.checkInterruptFlag();
            String key = FlowConstant.NODE_CUSTOM_INFO_MAP.get(this.getNodeId()).getParamNames().get(0);
            String uri = this.getCmpData(JSONObject.class).get(key, String.class);
            //FlowContextDto dto =  this.getRequestData();
            Robot robot = robotService.getDefaultRobot();
            //FlowPatrolPreAndEndTicketsDto ticketsDto = JSONObject.parseObject(dto.getTicketsTask()
            //        .getParseOrderParams(), FlowPatrolPreAndEndTicketsDto.class);

            //String auto = ticketsDto.getModalData().get("auto")== null ? "0":
            //        String.valueOf(ticketsDto.getModalData().get("auto"));
            //if (auto.equals("0")) {
            //    log.info("半自动任务:");
            //    return ;
            //}
            log.info("数据通知接口: {}", uri);
            //Map<String, Object> requestParams = Maps.newHashMap();
            uri = uri.replace("5401", robot.getRobotName());
            String result = restTemplate.postForObject(uri, "", String.class);
            log.info("数据通知接口" + result);
        } catch (Exception e) {
            log.info("数据请求失败:" + e.getMessage());
        }
    }

}
